<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>剩余参数</title>
</head>

<body>
    <script type="text/javascript">
        const sum = (...args) => {
            // 这里arg就是参数组成的数组
            let total = 0;
            // 这里的forEach用法类似java中lambda
            args.forEach(o => total += o);
            return total;
        }
        console.log(sum(10, 20));
        console.log(sum(10, 20, 30));

        //解构
        // let person = { name: 'heling', age: 17 }
        // let {name, age} = person
        // console.log(name);
        // console.log(age);

        let person = { name: 'heling', age: 17 }
        let {name} = person
        console.log(name);

        let {name:MyName, age:MyAge} = person;
        console.log(MyName);
        console.log(MyAge);


        //剩余参数和解构配合使用
        let student = ['zs', 'ls', 'ww'];
        let [s1, ...s2] = student;
        console.log(s1);
        console.log(s2);

    </script>
</body>

</html>